package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.sun.org.apache.bcel.internal.generic.NEW;
import com.ymatou.iapi.godmch.parameter.setChargeConfigBean;
import com.ymatou.iapi.godmch.service.setChargeConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.mapping.godmch.chargeconfigSqlProvider;
import com.ymttest.database.model.godmch.chargeconfig;
import com.ymttest.database.model.godmch.chargeconfigExample;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
/**
*设置商户功能收费配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_setChargeConfig{
	private static setChargeConfigBean bean;
	private static setChargeConfigCall call;
	
	DefGodMchWapper configMapper=new DefGodMchWapper();
	chargeconfigExample example=new chargeconfigExample();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置商户功能收费配置");
	}

	@Before
	public void caseUp() {
		bean=new setChargeConfigBean();
		call=new setChargeConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setChargeConfig_001() {
		Logger.start(true,"正例-设置商户功能收费配置-独立小程序、互动直播都收费");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId);
			bean.setFreeMiniApp(true);
			bean.setFreeLive(true);
			call.setData(bean);
			call.callService();		
			
			example.createCriteria().andMchIdEqualTo(mchId);
			chargeconfig config=configMapper.getChargeConfig(example).get(0);
			Logger.verifyEquals("200", new JSONObject(call.getReturnData()).get("status").toString(), "验证status");
			Logger.verifyEquals(true, config.getWxApp(), "验证数据库chargeconfig 中的WxApp");
			Logger.verifyEquals(true, config.getLiveVideo(), "验证数据库chargeconfig 中的LiveVideo");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_setChargeConfig_002() {
		Logger.start(true,"正例-设置商户功能收费配置-商户id不存在(目前开发没有对mchId做校验，此接口忽略)");
		try {

			bean.setMchId(99999);
			bean.setFreeMiniApp(true);
			bean.setFreeLive(true);
			call.setData(bean);
			call.callService();		
			
			example.createCriteria().andMchIdEqualTo(bean.getMchId());
			List<chargeconfig> configs=configMapper.getChargeConfig(example);
			Logger.verifyEquals("200", new JSONObject(call.getReturnData()).get("status").toString(), "验证status");
			Logger.verifyEquals(0, configs.size(), "验证数据库chargeconfig 中无新增数据");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setChargeConfig_003() {
		Logger.start(true,"正例-设置商户功能收费配置-独立小程序不免收费");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId);
			bean.setFreeMiniApp(false);
			bean.setFreeLive(true);
			call.setData(bean);
			call.callService();		
			
			example.createCriteria().andMchIdEqualTo(mchId);
			chargeconfig config=configMapper.getChargeConfig(example).get(0);
			Logger.verifyEquals("200", new JSONObject(call.getReturnData()).get("status").toString(), "验证status");
			Logger.verifyEquals(false, config.getWxApp(), "验证数据库chargeconfig 中的WxApp");
			Logger.verifyEquals(true, config.getLiveVideo(), "验证数据库chargeconfig 中的LiveVideo");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setChargeConfig_004() {
		Logger.start(true,"正例-设置商户功能收费配置-互动直播不免收费");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId);
			bean.setFreeMiniApp(true);
			bean.setFreeLive(false);
			call.setData(bean);
			call.callService();		
			
			example.createCriteria().andMchIdEqualTo(mchId);
			chargeconfig config=configMapper.getChargeConfig(example).get(0);
			Logger.verifyEquals("200", new JSONObject(call.getReturnData()).get("status").toString(), "验证status");
			Logger.verifyEquals(true, config.getWxApp(), "验证数据库chargeconfig 中的WxApp");
			Logger.verifyEquals(false, config.getLiveVideo(), "验证数据库chargeconfig 中的LiveVideo");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}